//
//  OrderCell.m
//  JiFengDaRen
//
//  Created by guest on 16/1/31.
//  Copyright © 2016年 SH_iOS. All rights reserved.
//

#import "OrderCell.h"
#import "OrderModel.h"
#import "ShoppingCartItemsModel.h"
#import "StoreModel.h"
@implementation OrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _payBtn.layer.cornerRadius = 5.f;
    _payBtn.layer.masksToBounds = YES;
    _payBtn.layer.borderColor = [UIColor colorWithWhite:0.95 alpha:1].CGColor;
    _payBtn.layer.borderWidth = 1.f;


}
-(void)setModel:(OrderModel *)model{

    _model = model;
    _nameLabel.text = model.storeModel.name;
    if (model.shoppingcartitems.count == 0) {
        return;
    }
    ShoppingCartItemsModel *itemsModel = model.shoppingcartitems[0];
    [_icon sd_setImageWithURL:[NSURL URLWithString:itemsModel.icon]];
    _orderId.text = [NSString stringWithFormat:@"订单号:%d",model._id];
    _allPrice.text = [NSString stringWithFormat:@"总价:%.2f",model.price];
    _date.text = model.order_time;
    
      _orderNum.text = [NSString stringWithFormat:@"数量:%d%@",itemsModel.quantity,itemsModel.unit];
    _orderStateLabel.text = [self status:model];
    if( model.is_payed  && model.status == 52  ){
    
      [_payBtn setTitle:@"确认收货" forState:UIControlStateNormal];
      
    }else if(model.is_payed && model.status != 52 && model.status != 199){
      [_payBtn setTitle:@"已付款" forState:UIControlStateNormal];
    }else if(!model.is_payed && model.status != 199){
        
        [_payBtn setTitle:@"立即付款" forState:UIControlStateNormal];
    }else if(model.is_payed && model.status == 199){
        [_payBtn setTitle:@"立即评价" forState:UIControlStateNormal];

    }
    

}
-(void)setModel2:(OrderModel *)model2{
    
        _nameLabel.text = model2.storeModel.name;
        //ShoppingCartItemsModel *itemsModel = model.shoppingcartitems[0];
       [_icon sd_setImageWithURL:[NSURL URLWithString:model2.storeModel.logo_small]];
        _orderId.text = [NSString stringWithFormat:@"订单号:%d",model2._id];
        _allPrice.text = [NSString stringWithFormat:@"总价:%.2f",model2.price];
        _date.text = model2.order_time;
        
        _orderNum.text = @"到店消费";
        _orderStateLabel.text = [self status:model2];
        if( model2.is_payed  && model2.status == 52  ){
            
            [_payBtn setTitle:@"确认收货" forState:UIControlStateNormal];
            
        }else if(model2.is_payed && model2.status != 52 && model2.status != 199){
            [_payBtn setTitle:@"已付款" forState:UIControlStateNormal];
        }else if(!model2.is_payed && model2.status != 199){
            
            [_payBtn setTitle:@"立即付款" forState:UIControlStateNormal];
        }else if(model2.is_payed && model2.status == 199){
            [_payBtn setTitle:@"立即评价" forState:UIControlStateNormal];
            
        }
        
        
    

}
-(NSString *)status:(OrderModel *)model{
    switch(model.status) {
        case 1:
            return @"待接单";
        case 5:
            return @"进行中";
        case 51:
            return @"待付款";
        case 52:
            return @"代发货";
        case 54:
            return @"退款中";
        case 199:
            return @"已完成";
        case 101:
            return @"拒接单";
        case 102:
            return @"订单取消";
        case 888:
            return @"店主代客下单";
    }
    return @"";

}
- (IBAction)payMoneyBtn:(UIButton *)sender {
    
    if([_delegate respondsToSelector:@selector(orderCell:state: orderModel:)]){
        [_delegate orderCell:self state:sender.currentTitle  orderModel:_model];
    }
}

@end
